home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d875.lha / Blanker / Source.lha / Source / Blankers / TextD / fText.c next >
Encoding:
C/C++ Source or Header  |  1993-05-24  |  8.4 KB  |  301 lines

  1. /** DoRev Header ** Do not edit! **
  2. *
  3. * Name             :  fText.c
  4. * Copyright        :  Free Software
  5. * Creation date    :  12-May-93
  6. * Translator       :  SAS/C 6.2
  7. * Compiler opts.   :  See Makefile
  8. *
  9. * Date       Rev  Author               Comment
  10. * ---------  ---  -------------------  ----------------------------------------
  11. * 12-May-93    1  Michael D. Bayne     Fixed problem with x pos = 0 at start
  12. * 12-May-93    0  Michael D. Bayne     Floating text blanker module
  13. *
  14. *** DoRev End **/
  15.  
  16. #include <exec/types.h>
  17. #include <exec/memory.h>
  18. #include <dos/dos.h>
  19. #include <intuition/intuition.h>
  20. #include <intuition/screens.h>
  21. #include <intuition/gadgetclass.h>
  22. #include <libraries/gadtools.h>
  23. #include <libraries/asl.h>
  24. #include <graphics/text.h>
  25. #include <graphics/gfxmacros.h>
  26. #include <graphics/copper.h>
  27. #include <graphics/videocontrol.h>
  28. #include <hardware/custom.h>
  29.  
  30. #include <clib/exec_protos.h>
  31. #include <clib/intuition_protos.h>
  32. #include <clib/graphics_protos.h>
  33. #include <clib/dos_protos.h>
  34. #include <clib/diskfont_protos.h>
  35. #include <clib/gadtools_protos.h>
  36. #include <clib/utility_protos.h>
  37. #include <clib/asl_protos.h>
  38. #include <clib/alib_protos.h>
  39.  
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43.  
  44. #include "Text.h"
  45. #include "/defs.h"
  46.  
  47. extern    struct    Custom far custom;
  48.  
  49. struct tPrefObject {
  50.     UBYTE text[128];
  51.     UBYTE fName[64];
  52.     UBYTE Speed;
  53.     UBYTE State;
  54.     UBYTE Cycle;
  55.     struct TextAttr Font;
  56. };
  57.  
  58. struct    tPrefObject    nP;
  59.  
  60. STATIC    const    UBYTE    VersTag[] = "$VER:Text 1.4 (5.12.93)";
  61.         UBYTE    infoString[] = "Bouncing Text Module";
  62.  
  63. void setTextPrefs( void )
  64. {
  65.         GT_SetGadgetAttrs( TextGadgets[GD_SPEED], TextWnd, 0L, GTSL_Level, nP.Speed, 0L );
  66.     GT_SetGadgetAttrs( TextGadgets[GD_FTXT], TextWnd, 0L, GTTX_Text, nP.fName, 0L );
  67.     if( nP.State ) GT_SetGadgetAttrs( TextGadgets[GD_FONT], TextWnd, 0L, GA_Disabled, TRUE, 0L );
  68.     else GT_SetGadgetAttrs( TextGadgets[GD_FONT], TextWnd, 0L, GA_Disabled, FALSE, 0L );
  69.     GT_SetGadgetAttrs( TextGadgets[GD_FSIZE], TextWnd, 0L, GTNM_Number, nP.Font.ta_YSize, 0L );
  70.     GT_SetGadgetAttrs( TextGadgets[GD_TXT], TextWnd, 0L, GTST_String, nP.text, 0L );
  71.     GT_SetGadgetAttrs( TextGadgets[GD_SWITCH], TextWnd, 0L, GTCY_Active, nP.State, 0L );
  72.     GT_SetGadgetAttrs( TextGadgets[GD_CYCLE], TextWnd, 0L, GTCY_Active, nP.Cycle, 0L );
  73. }
  74.  
  75. int OKClicked( void )
  76. {
  77.     return( QUIT );
  78. }
  79.  
  80. int CANCELClicked( void )
  81. {
  82.     return( CANCEL );
  83. }
  84.  
  85. int SPEEDClicked( void )
  86. {
  87.     nP.Speed = TextMsg.Code;
  88.     return( OK );
  89. }
  90.  
  91. int SWITCHClicked( void )
  92. {
  93.     nP.State = TextMsg.Code;
  94.     setTextPrefs();
  95.     return( OK );
  96. }
  97.  
  98. int CYCLEClicked( void )
  99. {
  100.     nP.Cycle = TextMsg.Code;
  101.     return( OK );
  102. }
  103.  
  104. int FONTClicked( void )
  105. {
  106.     struct FontRequester *fReq;
  107.  
  108.     if( fReq = ( struct FontRequester * )AllocAslRequestTags( ASL_FontRequest, ASL_FontName, (ULONG)nP.fName,
  109.         ASL_FontHeight, nP.Font.ta_YSize, ASL_MaxHeight, 100, TAG_DONE )) {
  110.         if( AslRequestTags( fReq, ASLFO_Window, TextWnd, ASLFO_SleepWindow, TRUE, ASLFO_TitleText,
  111.             (ULONG)"Please choose a font...", 0L )) {
  112.             strcpy( nP.fName, fReq->fo_Attr.ta_Name );
  113.             nP.Font.ta_YSize = fReq->fo_Attr.ta_YSize;
  114.         }
  115.         FreeAslRequest( fReq );
  116.     }
  117.     setTextPrefs();
  118.     return( OK );
  119. }
  120.  
  121. int TXTClicked( void )
  122. {
  123.     strcpy( nP.text, (( struct StringInfo * )( TextGadgets[GD_TXT] )->SpecialInfo )->Buffer );
  124.     return( OK );
  125. }
  126.  
  127. int TextVanillaKey( void )
  128. {
  129.     switch( TextMsg.Code ) {
  130.     case 'o':
  131.         return( QUIT );
  132.     case 'c':
  133.         return( QUIT );
  134.     case 'f':
  135.         return( FONTClicked());
  136.     case 's':
  137.         GT_SetGadgetAttrs( TextGadgets[GD_SPEED], TextWnd, 0L, GTSL_Level, ++(nP.Speed) > 50 ?
  138.             nP.Speed = 50 : nP.Speed, 0L );
  139.         return( OK );
  140.     case 'S':
  141.         GT_SetGadgetAttrs( TextGadgets[GD_SPEED], TextWnd, 0L, GTSL_Level, --(nP.Speed) < 1 ?
  142.             nP.Speed = 1 : nP.Speed, 0L );
  143.         return( OK );
  144.     default:
  145.         return( OK );
  146.     }
  147. }
  148.  
  149. void prefs( UBYTE *prefData )
  150. {
  151.     LONG    retval = OK;
  152.  
  153.     CopyMem(( struct tPrefObject * )prefData, &nP, sizeof( struct tPrefObject ));
  154.     nP.Font.ta_Name = nP.fName;
  155.     if( !SetupScreen() ) { if( !OpenTextWindow()) {
  156.         CloseDownScreen();
  157.         setTextPrefs();
  158.         while( 1 ) {
  159.             WaitPort( TextWnd->UserPort );
  160.             retval = HandleTextIDCMP();
  161.             if( retval == QUIT ) {
  162.                 CopyMem( &nP, prefData, sizeof( struct tPrefObject ));
  163.                 break;
  164.             }
  165.             if( retval == CANCEL ) break;
  166.         }
  167.         CloseTextWindow();
  168.     } } else CloseDownScreen();
  169. }
  170.  
  171. VOID newCopperList( LONG height, struct ViewPort *vp )
  172. {
  173.     #define NUMCOLORS 45
  174.  
  175.     struct    UCopList    *uCopList;
  176.     struct    TagItem    uCopTags[] = { { VTAG_USERCLIP_SET, 0L }, { VTAG_END_CM, 0L } };
  177.     register    USHORT    i, index = rand()%NUMCOLORS, spc;
  178.         UWORD    spectrum[] = {  0x0F00, 0x0E10, 0x0D20, 0x0C30, 0x0B40, 0x0A50, 0x0960, 0x0870, 0x0780, 0x0690,
  179.                 0x05A0, 0x04B0, 0x03C0, 0x02D0, 0x01E0, 0x00F0, 0x00E1, 0x00D2, 0x00C3, 0x00B4,
  180.                 0x00A5, 0x0096, 0x0087, 0x0078, 0x0069, 0x005A, 0x004B, 0x003C, 0x002D, 0x001E,
  181.                 0x000F, 0x010E, 0x020D, 0x030C, 0x040B, 0x050A, 0x0609, 0x0708, 0x0807, 0x0906,
  182.                 0x0A05, 0x0B04, 0x0C03, 0x0D02, 0x0E01 };
  183.     
  184.     if( uCopList = ( struct UCopList * )AllocMem( sizeof( struct UCopList ), MEMF_PUBLIC|MEMF_CLEAR )) {
  185.  
  186.         spc = height/NUMCOLORS;
  187.  
  188.         CINIT( uCopList, NUMCOLORS );
  189.  
  190.         for( i = 0; i<NUMCOLORS; ++i ) {
  191.             CWAIT( uCopList, i*spc, 0 );
  192.             CMOVE( uCopList, custom.color[1], spectrum[(i+index)%NUMCOLORS] );
  193.         }
  194.  
  195.         CEND( uCopList );
  196.  
  197.         Forbid();
  198.         vp->UCopIns = uCopList;
  199.         Permit();
  200.  
  201.         VideoControl( vp->ColorMap, uCopTags );
  202.  
  203.         RethinkDisplay();
  204.     }
  205. }
  206.  
  207. void blank( struct bMessage *Msg )
  208. {
  209.     struct    TextFont    *font;
  210.     struct    tPrefObject    *nP = ( struct tPrefObject * )Msg->prefData;
  211.     struct    Screen        *TextScr;
  212.     UBYTE    vals[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4,
  213.         3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  214.     UBYTE    scrText[128], c1 = 0, c2 = 14, c3 = 28;
  215.     ULONG    x = 2, y, Wid, Hei, len, numc, base, count;
  216.     LONG    dx = 1, dy = 1, delay, cycle = 0;
  217.     FILE    *textFile;
  218.  
  219.     srand( (ULONG)VBeamPos() );
  220.  
  221.     if( nP->State ) {
  222.         if( textFile = fopen( nP->text, "r" )) {
  223.             fscanf( textFile, "%lu", &count );
  224.             numc = rand()%(count+1);
  225.             while((( fgetc( textFile ) == '\n' )?++cycle:cycle ) < numc );
  226.             fscanf( textFile, "%s %d ", nP->fName, &delay );
  227.             nP->Font.ta_YSize = (WORD)delay;
  228.             fgets( scrText, 128, textFile );
  229.             scrText[strlen( scrText )-1] = 0;
  230.             fclose( textFile );
  231.         } else sprintf( scrText, "Could not open: %s", nP->text );
  232.     } else strcpy( scrText, nP->text );
  233.  
  234.     nP->Font.ta_Name = nP->fName;
  235.     font = OpenDiskFont( &( nP->Font ));
  236.     base = font->tf_Baseline;
  237.  
  238.     TextScr = OpenScreenTags( 0l, SA_DisplayID, Msg->sMod, SA_Depth, 1, SA_Quiet, TRUE, SA_Overscan,
  239.         OSCAN_STANDARD, SA_Font, &( nP->Font ), TAG_DONE );
  240.  
  241.     Wid = TextScr->Width;
  242.     Hei = TextScr->Height;
  243.  
  244.     numc = strlen( scrText );
  245.     while(( len = TextLength( &(TextScr->RastPort), scrText, numc )) >= Wid-5 ) numc--;
  246.  
  247.     y = rand()%( Hei - nP->Font.ta_YSize );
  248.  
  249.     SetRGB4( &(TextScr->ViewPort), 0, 0L, 0L, 0L );
  250.     switch( nP->Cycle ) {
  251.     case 0:
  252.         SetRGB4( &(TextScr->ViewPort), 1, vals[c1], vals[c2], vals[c3] );
  253.         break;
  254.     case 1:
  255.         SetRGB4( &(TextScr->ViewPort), 1, rand()%15 + 1, rand()%15 + 1, rand()%15 + 1 );
  256.         break;
  257.     case 2:
  258.         SetRGB4( &(TextScr->ViewPort), 1, 15, 15, 15 );
  259.         break;
  260.     case 3:
  261.         newCopperList( Hei, &( TextScr->ViewPort ));
  262.         break;
  263.     }        
  264.  
  265.     SetAPen( &(TextScr->RastPort), 1 );
  266.     Move( &(TextScr->RastPort), x, y + base );
  267.     Text( &(TextScr->RastPort), scrText, numc );
  268.  
  269.     delay = 51 - nP->Speed;
  270.  
  271.     while(!( SetSignal( 0L, 0L )&SIGBREAKF_CTRL_C )) {
  272.         if(!( ++count%delay )) {
  273.             if( !nP->Cycle && !(count%(10*delay))) SetRGB4( &(TextScr->ViewPort), 1, vals[c1 = ++c1%42],
  274.                 vals[c2 = ++c2%42], vals[c3 = ++c3%42] );
  275.             ScrollRaster( &(TextScr->RastPort), dx, dy, x-1, y-1, x+1+len, y+1+nP->Font.ta_YSize );
  276.             x -= dx; y -= dy;
  277.             if( x < 2 ) dx = -1;
  278.             else if( x > Wid-len-2 ) dx = 1;
  279.             if( y < 2 ) dy = -1;
  280.             else if( y > Hei-nP->Font.ta_YSize-2 ) dy = 1;
  281.         }
  282.     }
  283.     SetSignal( 0L, SIGBREAKF_CTRL_C );
  284.  
  285.     if( font ) CloseFont( font );
  286.     CloseScreen( TextScr );
  287. }
  288.  
  289. void defaults( UBYTE *prefData )
  290. {
  291.     strcpy( (( struct tPrefObject * )prefData )->text, "Every dog should have a boy" );
  292.     strcpy( (( struct tPrefObject * )prefData )->fName, "topaz.font" );
  293.     (( struct tPrefObject * )prefData )->Font.ta_Name = (( struct tPrefObject * )prefData )->fName;
  294.     (( struct tPrefObject * )prefData )->Font.ta_YSize = 11;
  295.     (( struct tPrefObject * )prefData )->Font.ta_Style = FS_NORMAL;
  296.     (( struct tPrefObject * )prefData )->Font.ta_Flags = FPB_ROMFONT;
  297.     (( struct tPrefObject * )prefData )->Speed = 10;
  298.     (( struct tPrefObject * )prefData )->State = 0;
  299.     (( struct tPrefObject * )prefData )->Cycle = 0;
  300. }
  301.